<?php
require_once 'PHPUnit/Framework.php';
$dbms = "mysql";
$pathAdjust = "../../../scripts/";
if((@include_once "{$pathAdjust}initIncludePaths.inc") == "1")
    echo "included from $pathAdjust\r\n";
else {
    $pathAdjust = "../../scripts/";
    if((@include_once "{$pathAdjust}initIncludePaths.inc") == "1")
        echo "included from $pathAdjust\r\n";
    else {
        $pathAdjust = "../scripts/";
        if((@include_once "{$pathAdjust}initIncludePaths.inc") == "1")
            echo "included from $pathAdjust\r\n";
        else {
            $pathAdjust = "scripts/";
            if((@include_once "{$pathAdjust}initIncludePaths.inc") == "1")
                echo "included from $pathAdjust\r\n";
            else {
                $pathAdjust = "./";
                if((@include_once "{$pathAdjust}initIncludePaths.inc") == "1")
                    echo "included from $pathAdjust\r\n";
            }
        }
    }
}

include_once "dbFac.inc";
include_once "database.inc";


class DatabaseTest extends PHPUnit_Framework_TestCase {
    private $db = null;

    protected function setUp() {
        $dbf = new DatabaseFactory("mysql","localhost","test2DB","root","");
        $this->db = $dbf->connect();
    }
    protected function tearDown()
    {
        unset($this->db);
    }
    public function testIsConnected() {
        $this->assertEquals(   true,
                                $this->db->isConnected());
    }
    public function testConnect() {
        $this->db->connect("","","","");
        $this->assertEquals($this->db->isConnected(), false);
        $this->db->connect("localhost","2db","root","");
        $this->assertEquals($this->db->isConnected(), true);    //real database connect
        $this->db->connect("localhost","test2DB","root","");
        $this->assertEquals($this->db->isConnected(), true);    //test database connect
    }
    public function testExecuteSQL() {
        $sql = "SHOW TABLES";
        $res = $this->db->executeSQL($sql);
        $this->assertEquals($res,true);

        $sql = "SELECT FROM Users";
        $res = $this->db->executeSQL($sql);
        $this->assertEquals($res,false);

        $sql = "SELECT * FROM Users";
        $res = $this->db->executeSQL($sql);
        $this->assertEquals($res,true);
    }
    public function testGetResult() {
        $sql = "SHOW TABLES";
        $res = $this->db->getResult($sql);
        $found = false;
        foreach($res as $row) {
            if($row['Tables_in_test2db'] == "images")
                $found = true;
        }
        $this->assertEquals($found,true);
    }
    public function testTableSpaceExists() {
        
    }
    public function testHasAdmin() {

    }
    public function testCreateTableSpace() {
        //is being tested in 00Test.php in order to provide a test2DB for all following tests
        //Problem here is include_once paradigm.
    }
}

?>